package atlantik.ui;

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;

import modelz.UpdateListener;

import atlantik.game.action.AtlantikAction;

class ClientAction<T extends AtlantikAction<T>> extends AbstractAction implements UpdateListener<T> {

	private static final long serialVersionUID = 6009335074727417445L;

	private final T action;

	protected ClientAction(T action) {
		this.action = action;
		action.addListener(this);
	}

	public void actionPerformed(ActionEvent event) {
		action.perform();
	}

	public void updated(T action) {
		setEnabled(action.canPerform());
		putValue(Action.NAME, action.getCaption());
	}

}
